<template>
	<view>
		<remind-carinfo :dataBean="carInfo"></remind-carinfo>



		<view class="boxContrainer">
			<view class="titlBox">
				<text class="title">交强险信息</text>
				<text style="line-height: 80rpx; color: #E93131;"
					v-if="detailInfo.jqDay>0">剩余{{detailInfo.jqDay}}天到期</text>
			</view>
			<view v-if="detailInfo.jqId" class="contentBox">
				<view class="text-line">
					<text class="text-name">交强险开始时间:</text>
					<text class="text-value">{{detailInfo.jqStartTime|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">交强险结束时间:</text>
					<text class="text-value">{{detailInfo.jqEndTime|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">交强险保单号:</text>
					<text class="text-value">{{detailInfo.jqNo|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">保险公司:</text>
					<text class="text-value">{{detailInfo.jqCompany|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">费用:</text>
					<text class="text-value">{{detailInfo.jqPremium|filterNull}}</text>
				</view>


				<view class="text-line">
					<text class="text-name">保单附件</text>
					<text v-if="!detailInfo.jqPolicy" class="text-value">--</text>
					<template style="margin-left: 30rpx;" v-else class="text-value">
						<u-album v-if="imgs1.length>0" :urls="imgs1" multipleSize="100"></u-album>
						<!-- <a v-else :href="settings.baseImageUrl+detailInfo.jqPolicy" download> 下载保单</a> -->
						<view v-else class="btn-detail" @click="downloadPolicy(detailInfo.jqPolicy)">
							查看保单
						</view>
					</template>
				</view>


			</view>

			<view v-else class="nodata">
				<image src="/car/static/no_qx.png" mode=""></image>
				<text>暂无交强险</text>
			</view>


			<view v-if="false">
				<u-line color="#efefef" dashed>
				</u-line>

				<view class="btn-detail" @click="addInsurance(1)">
					续 保
				</view>
			</view>


		</view>

		<view class="boxContrainer">
			<view class="titlBox">
				<text class="title">商业险信息</text>
				<text style="line-height: 80rpx; color: #E93131;"
					v-if="detailInfo.syDay>0">剩余{{detailInfo.syDay}}天到期</text>
			</view>

			<view v-if="detailInfo.syId" class="contentBox">

				<view class="text-line">
					<text class="text-name">商业险开始时间:</text>
					<text class="text-value">{{detailInfo.syStartTime|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">商业险结束时间:</text>
					<text class="text-value">{{detailInfo.syEndTime|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">商业险保单号:</text>
					<text class="text-value">{{detailInfo.syNo|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">保险公司:</text>
					<text class="text-value">{{detailInfo.syCompany|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">费用:</text>
					<text class="text-value">{{detailInfo.syPremium|filterNull}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">保单附件</text>
					<text v-if="!detailInfo.syPolicy" class="text-value">--</text>
					<template style="margin-left: 30rpx;" v-else class="text-value">
						<u-album v-if="imgs2.length>0" :urls="imgs2" multipleSize="100"></u-album>
						<!-- <a v-else :href="settings.baseImageUrl+detailInfo.jqPolicy" download> 下载保单</a> -->
						<view v-else class="btn-detail" @click="downloadPolicy(detailInfo.syPolicy)">
							查看保单
						</view>
					</template>
				</view>
			</view>

			<view v-else class="nodata">
				<image src="/car/static/no_qx.png" mode=""></image>
				<text>暂无商业险</text>
			</view>

			<view v-if="false">
				<u-line color="#efefef" border-style="dashed" style="display: block;" v-if="dataBean.insuranceButton">
				</u-line>

				<view class="btn-detail" v-if="dataBean.insuranceButton" @click="addInsurance(2)">
					续 保
				</view>
			</view>


		</view>
	</view>
</template>

<script>
	import remindCarinfo from '@/components/remindCarInfo/remind-carinfo.vue';
	import settings from '@/settings.js'
	import {
		getInfo
	} from '@/api/car-api.js'
	export default {
		components: {
			remindCarinfo,
		},
		data() {
			return {
				carInfo: {},
				detailInfo: {},
				imgs1: [],
				imgs2: []
			}
		},
		onLoad(op) {
			this.carInfo = op;
			this.getData();
		},
		methods: {

			getData() {
				getInfo(this.carInfo.id).then(res => {
					this.detailInfo = res.data.carBasic;

					if (this.detailInfo.syPolicy && this.detailInfo.syPolicy.indexOf('.pdf') == -1) {
						this.imgs1.push(settings.baseImageUrl + this.detailInfo.syPolicy);
					}
					if (this.detailInfo.jqPolicy && this.detailInfo.jqPolicy.indexOf('.pdf') == -1) {
						this.imgs2.push(settings.baseImageUrl + this.detailInfo.jqPolicy);
					}
				})
			},

			//新增续保
			addInsurance(type) {
				uni.navigateTo({
					url: './add?pageType=' + type
				})
			},
			downloadPolicy(url) {
				uni.downloadFile({
					url: settings.baseImageUrl + url,
					success: function(res) {
				  var filePath = res.tempFilePath;
				  uni.openDocument({
							filePath: filePath,
							showMenu: true,
				   success: function(res) {
								console.log('打开文档成功');
							}
						});
					}
				});
			}

		}
	}
</script>

<style lang="scss" scoped>
	.btn-detail {
		width: 180rpx;
		height: 60rpx;
		border-radius: 50rpx;
		color: white;
		text-align: center;
		background-color: $blue15;
		font-size: 26rpx;
		line-height: 60rpx;
		align-self: flex-end;
		margin: 10rpx 20rpx 10rpx;
	}
</style>
